#ifndef LIB_DEBOUNCE_H
#define LIB_DEBOUNCE_H

#include <stdint.h>

/** \brief Debouncer state */
typedef struct
{
  uint_fast8_t integrator_state; //!< Integrator state
  uint_fast8_t output_state; //!< Output state
  uint_fast8_t debounce_time_in_ms; //!< How long a button is debounced in milliseconds.
  uint_fast8_t input_sampling_freq_in_hz; //!< Debouncer button sampling frequency in Hertz.
  uint_fast8_t integrator_max_value; //!< Integrator max value
} deb_t;

/** \brief Debouncer state init
\param[out] deb Struct to init
\param[in] debounce_time_in_ms Period of debounce time in milliseconds
\param[in] input_sampling_freq_in_hz Button input sampling frequency in hertz
 */
void debounce_init(deb_t *deb, uint_fast8_t debounce_time_in_ms, uint_fast8_t input_sampling_freq_in_hz);

/** \brief Debouncer button
\param[in] input Input sample
\param[out] deb Debounce struct to update
 */
void debounce(uint_fast8_t input, deb_t *deb);

#endif
